var validator = function(rules, messages) {
    var handleSubmit = function() {
        $J('.inputform').validate({
            errorElement : 'span',
            errorClass : 'help-block',
            focusInvalid : true, //让错误对象获得焦点
        	rules: rules,
        	messages: messages,
            highlight : function(element) {
                $J(element).closest('.form-group').addClass('has-error');
            },
            success : function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },
            errorPlacement : function(error, element) {
                element.parents('div .col-lg-6').append(error);
            },
            submitHandler : function(form) {
                form.submit();
            }
        });

        $J('.inputform input').keypress(function(e) {
            if (e.which == 13) {
                if ($J('.inputform').validate().form()) {
                    $J('.inputform').submit();
                }
                return false;
            }
        });
    }
    return {
        init : function() {
            handleSubmit();
        }
    };
};
